package com.ruoyi.web.controller.honor.person;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.honor.person.PersonalHonor;
import com.ruoyi.system.service.honor.IPersonalHonorService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 个人荣誉Controller
 * 
 * @author ruoyi
 * @date 2025-07-29
 */
@RestController
@RequestMapping("/honor/person")
public class PersonalHonorController extends BaseController
{
    @Autowired
    private IPersonalHonorService personalHonorService;

    /**
     * 查询个人荣誉列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PersonalHonor personalHonor)
    {
        startPage();
        List<PersonalHonor> list = personalHonorService.selectPersonalHonorList(personalHonor);
        return getDataTable(list);
    }

    /**
     * 导出个人荣誉列表
     */
    @Log(title = "个人荣誉", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PersonalHonor personalHonor,
     @RequestParam(required = false) String exportFields)
    {
        List<PersonalHonor> list = personalHonorService.selectPersonalHonorList(personalHonor);
        ExcelUtil<PersonalHonor> util = new ExcelUtil<PersonalHonor>(PersonalHonor.class);
        // 如果传递了导出字段，则进行处理
        if (StringUtils.isNotBlank(exportFields)) {
            // 将逗号分隔的字段转为数组，调用showColumn指定显示字段
            String[] fields = exportFields.split(",");
            util.showColumn(fields); // 关键：使用ExcelUtil已有的showColumn方法
        }
        util.exportExcel(response, list, "个人荣誉数据");
    }

    /**
     * 获取个人荣誉详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(personalHonorService.selectPersonalHonorById(id));
    }

    /**
     * 新增个人荣誉
     */
    @Log(title = "个人荣誉", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PersonalHonor personalHonor)
    {
        return toAjax(personalHonorService.insertPersonalHonor(personalHonor));
    }

    /**
     * 修改个人荣誉
     */
    @Log(title = "个人荣誉", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PersonalHonor personalHonor)
    {
        return toAjax(personalHonorService.updatePersonalHonor(personalHonor));
    }

    /**
     * 删除个人荣誉
     */
    @Log(title = "个人荣誉", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(personalHonorService.deletePersonalHonorByIds(ids));
    }
}
